import pathOr from 'ramda/es/pathOr';
import fetch from 'API/fetch';
function json2params(json, slice = '&') {
	return Object.keys(json)
		.reduce((acc, item) => {
			return String(acc) + item + '=' + json[item] + slice;
		}, '')
		.slice(0, -1);
}
export const queryGQLBuilder = data => {
	const params =
		data && Object.keys(data).length > 0 ? '?' + json2params(data) + '' : '';
	return fetch('/api/v2/alerts/detail_list' + params, { mathod: 'GET' });
};

export const getTotal = pathOr(1, ['dataPgination', 'data', 'count']);
export const getTableRows = pathOr([], ['dataPgination', 'data', 'items']);
export const queryVariablesBuilder = ({ filter, page, perPage }) => ({
	page,
	limit: perPage,
	taskCategory: filter?.taskCategory,
	taskType: filter?.taskType,
	targetSearch: filter?.targetSearch,
	taskTriggerType: filter?.taskTriggerType,
	startTime: filter?.createTimeGTE,
	endTime: filter?.createTimeLTE,
});
